#include "test_Message.h"
#include "app/app_message.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>

void test_message()
{
    Message message;
    unsigned char binary[] = {0x02, 0x04, 0xAF, 0xBF, 0xAA, 0xBB, 0xCC, 0xDD};
    char *json_str = "{\"connection_type\":1,\"id\":\"AFBF\",\"message\":\"AABBCCDD\"}";
    char buf[100];

    // json到binary
    app_message_initByJsonStr(&message, json_str);
    app_message_saveBinary(&message, buf, 100);
    assert(memcmp(buf, binary, 8) == 0);

    // binary到json
    app_message_initByBinary(&message, BLUETOOTH, binary, 8);
    app_message_saveJson(&message, buf, 100);
    assert(strcmp(json_str, buf) == 0);
}